package com.jf.alibaba.config;

import com.alibaba.cloud.ai.memory.jdbc.MysqlChatMemoryRepository;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2025-06-29
 * Time:14:24
 */
@Component
public class MysqlMemoryConfig {
    @Bean
    public ChatMemory mysqlMemory(JdbcTemplate jdbcTemplate) {
        ChatMemoryRepository memoryRepository = MysqlChatMemoryRepository.mysqlBuilder()
                .jdbcTemplate(jdbcTemplate)
                .build();
        return MessageWindowChatMemory.builder()
                .chatMemoryRepository(memoryRepository)
                .build();
    }
}
